/**
 * 连接数据库,并且注册模型
 * Created by luckyjing on 16/2/5.
 */
var config = require('./config'),
    mongoose = require('mongoose');
module.exports = function () {
    mongoose.set('debug', true);
    mongoose.connect(config.db);
    var db = mongoose.connection;
    db.on('error', console.error.bind(console, '数据库连接失败'));
    db.once('open', function () {
        console.log('数据库连接成功');
    });

    
    require('../app/models/user.server.model');
    require('../app/models/rent.server.model');
    require('../app/models/tool.server.model');
    return db;
};